import * as Cesium from 'cesium';
export default async function modifyBuild(viewer) {
  // 添加 3D 建筑
  let tiles3d = await Cesium.createOsmBuildingsAsync();

  // 定义建筑自定义样式
  let customShader = new Cesium.CustomShader({
    //片元着色器
    fragmentShaderText: `
        void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material) {
            //瓦片颜色
            vec3 positionMC = fsInput.attributes.positionMC * 2.25;
            float strength = positionMC.z/900.0;
            material.diffuse = vec3(strength,0.3*strength,strength * 12.0);

            //动态光环
            //  czm_frameNumber获取当前帧数
            //  fract(x),返回x的小鼠部分
            float time = fract(czm_frameNumber/60.0*0.1); //此处括号内分母为移动速度
            //实现往返的操作
             time = abs(time -0.5)*2.0;
            //time = sin(time);
            float diff = abs(clamp(positionMC.z/500.0,0.0,1.0) - time);
            diff = step(0.1,diff);
            material.diffuse += vec3(0.5)*(1.0-diff);
        }`,
  });
  // 3D 瓦片中修改属性
  tiles3d.customShader = customShader;
  // 挂载 3D 瓦片
  const osmBuildings = viewer.scene.primitives.add(tiles3d);
}
